//
//  XHDemoViewModel.m
//  XHFoundationModule
//
//  Created by xinph on 2020/3/13.
//  Copyright © 2020 xinph. All rights reserved.
//

#import "XHDemoViewModel.h"
#import "DemoWebViewController.h"
#import "DemoWebViewModel.h"

@implementation XHDemoViewModel

- (void)initialize
{
    [super initialize];
    
    self.title = @"铁憨憨";
    /// 设置tableView的样式
    self.style = UITableViewStyleGrouped;
    /// 隐藏导航栏的细线
    self.prefersNavigationBarBottomLineHidden = YES;
    
    /// 允许下拉刷新+上拉加载
    self.shouldPullDownToRefresh = YES;
    self.shouldPullUpToLoadMore = YES;
    
    //允许进页面就请求数据
    self.shouldRequestRemoteDataOnViewDidLoad = YES;
    
    /// 显示的数据是每页八条说说
    self.perPage = 8;
    self.shouldEndRefreshingWithNoMoreData = YES;
}

 /// 请求指定页的网络数据
- (RACSignal *)requestRemoteDataSignalWithPage:(NSUInteger)page {
    @weakify(self)
    return [RACSignal createSignal:^RACDisposable * _Nullable(id<RACSubscriber>  _Nonnull subscriber) {
        @strongify(self)
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(.75f * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            self.dataSource = @[@1, @2];
            
            [subscriber sendNext:nil];
            [subscriber sendCompleted];
        });
        
        return nil;
    }];
}

- (void)didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSURLRequest *request = [[NSURLRequest alloc] initWithURL:[NSURL URLWithString:@"https://www.baidu.com"]];
    DemoWebViewModel *webModel = [[DemoWebViewModel alloc] initWithServices:nil params:@{XHViewModelRequestKey: request}];
    DemoWebViewController *webVC = [[DemoWebViewController alloc] initWithViewModel:webModel];
    UIViewController *vc = kCurrentViewController;
    [vc.navigationController pushViewController:webVC animated:true];
}


@end
